<%--
  Created by IntelliJ IDEA.
  User: 64901
  Date: 2022/10/7
  Time: 21:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <meta charset="utf-8">
  <title>hr注册</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/public.css" media="all">

</head>
<body>
<%-- 添加和修改窗口 --%>
<div>
  <form class="layui-form" style="width:90%;" id="dataFrm" lay-filter="dataFrm">
    <div class="layui-form-item">
      <label class="layui-form-label required">高管名称</label>
      <div class="layui-input-block">
        <input type="hidden" name="manageId">
        <input type="text" name="manageName" lay-verify="required" lay-reqtext="你名字还没写来" placeholder="请输入名字" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">高管照片</label>

      <div class="layui-input-block">
        <button type="button" class="layui-btn" id="test1">
          <i class="layui-icon">&#xe67c;</i>上传图片
        </button>
      </div>

      <label class="layui-form-label">图片预览</label>
      <div class="layui-input-block" style="margin-top: 13px">
        <img id="image" style="max-height: 150px">
      </div>

      <div class="layui-input-block" hidden>
        <input type="hidden" name="manageImg" lay-verify="required" lay-reqtext="你图片还没加来"  value="" id="manageImg" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">高管简介</label>
      <div class="layui-input-block">
        <textarea name="manageIntroduct" class="layui-textarea" placeholder="个人简介"></textarea>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">高管职位</label>
      <div class="layui-input-block">
        <input type="text" name="managePosition" lay-verify="required"  value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label required">高管账号</label>
      <div class="layui-input-block">
        <input type="text" name="manageUsername" lay-verify="required" lay-reqtext="你账号还没写"  value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">高管密码</label>
      <div class="layui-input-block">
        <input type="password" name="managePassword" lay-verify="required" lay-reqtext="你密码还没写"  value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">公司id</label>
      <div class="layui-input-block">
        <input type="number" id = "companyId" name="companyId" lay-verify="required" lay-reqtext="公司id还没写" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">状态</label>
      <div class="layui-input-block">
        <input type="number" name="manageStatus" value="1" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
      <div class="layui-input-block" style="text-align: center;">
        <button type="button" class="layui-btn" lay-submit lay-filter="doSubmit"><span
                class="layui-icon layui-icon-add-1"></span>提交
        </button>
        <button type="reset" class="layui-btn layui-btn-warm"><span
                class="layui-icon layui-icon-refresh-1"></span>重置
        </button>
        <button type="button" class="layui-btn"  id="initCompany"><span
                class="layui-icon layui-icon-add-1"></span>创建公司
        </button>
      </div>
    </div>
  </form>
</div>
<script src="${pageContext.request.contextPath}/static/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
  layui.use(['form','layer','upload'], function () {
    var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            upload = layui.upload;
    var companyId = window.sessionStorage.getItem("companyId")
    $("#companyId").val(companyId)
    //执行实例
    let uploadInst = upload.render({
      elem: '#test1' //绑定元素
      ,url: '${pageContext.request.contextPath}/test/upload' //上传接口
      ,done: function(res){
        if (res.imgUrl != null){
          layer.msg("上传成功");
          //获得图片的路径
          let src = res.imgUrl;
          //将图片进行回显
          $("#image").attr("src",src);
          //将图片的地址赋值给 form的隐藏域
          $("#manageImg").attr("value",src);
        }
      }
      ,error: function(){
        //请求异常回调
      }
    });

    var url = "${pageContext.request.contextPath}/backStageCompanyManage/save";
    //监听表单提交事件
    form.on("submit(doSubmit)",function (data) {
      //判断是否有这个公司
      $.get("${pageContext.request.contextPath}/backStageCompanyDetail/selectById?companyId="+data.field.companyId,function(result){

        if(result.code === 20000){
          $.post(url,data.field,function(result){
            console.log(result)
            if(result.code === 20000){
              location.href="backStageLogin.jsp"
            }
            //提示信息
            layer.msg(result.msg);
          },"json");
        }else {
          //提示信息
          layer.msg("没有该公司，可以注册一个");
        }

      },"json");

      //禁止页面刷新
      return false;
    });

    $("#initCompany").click(function (data) {
      location.href = "backStageRegistryCompany.jsp"
    });
  });
</script>
</body>
</html>
